package jianzhi_offer;

public class _55_删除链表中重复的结点 {
    public static void main(String[] args) {
        _55_删除链表中重复的结点 test = new _55_删除链表中重复的结点();
        ListNode n1 = new ListNode(3);
        ListNode n2 = new ListNode(3);
        ListNode n3 = new ListNode(3);
        ListNode n4 = new ListNode(3);
        n1.next = n2;
        n2.next = n3;
        n3.next = n4;
        ListNode.printList(n1);
        ListNode res = test.deleteDuplication(n1);
        ListNode.printList(res);
    }

    public ListNode deleteDuplication(ListNode pHead)
    {
        if(pHead == null || pHead.next == null) return pHead;
        ListNode fake = new ListNode(-1);
        fake.next = pHead;
        ListNode run = fake;
        while (run != null && run.next != null){
            ListNode check = run.next;
            while(check.next != null && check.next.val == run.next.val) check = check.next;
            if(check == run.next) run = run.next;
            else{
                run.next = check.next;
            }
        }
        return fake.next;
    }
}
